package com.mchat.config;

import io.jsonwebtoken.JwtParser;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@Data
public class JwtConfig {

    private String secret;


    private Long expiration;
    @Bean
    public JwtParser createParser( @Value("${jwt.secret}") String secret,@Value("${jwt.expiration}") Long expiration){
        this.expiration=expiration;
        this.secret=secret;
        return Jwts.parserBuilder().setSigningKey(Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8))).build();
    }
}
